package com.tree.common.dto;

import com.tree.common.constants.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

import java.io.Serializable;

/**
 * @ClassName com.demo.common.dto
 * Description: <类功能描述>. <br>
 * <p>
 * <使用说明>
 * </p>
 * @Author tree
 * @Date 2019-05-26 00:22
 * @Version 1.0
 */
@Getter
public class FrontResponse<T> implements Serializable {

    static final long serialVersionUID = 1L ;
    @ApiModelProperty(value = "结果编码", dataType = "int", required = true)
    private int code;

    @ApiModelProperty(value = "结果消息", dataType = "String" , required = true)
    private String message;

    @ApiModelProperty(value = "返回对象", required = true)
    private T data;


    private String traceId;

    public FrontResponse(){
    }

    public FrontResponse(int code){
        this();
        this.code = code;
    }
    public FrontResponse(int code, String message){
        this();
        this.code = code;
        this.message = message;
    }

    public FrontResponse(int code, String message, T data){
        this();
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public FrontResponse<T> success(){
        this.code = ErrorCodeConstants.SUCCESS;
        return this;
    }

    public FrontResponse<T> fail(){
        this.code = ErrorCodeConstants.FAIL;
        return this;
    }

    public FrontResponse<T> setCode(int code){
        this.code = code;
        return this;
    }


    public FrontResponse<T> setMessage(String message){
        this.message = message;
        return this;
    }

    public FrontResponse<T> setObject(T object){
        this.data = object;
        return this;
    }

}
